import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';

@Injectable()
export class FileSizeValidationPipe implements PipeTransform {
    constructor(private readonly maxSize: number = 1024 * 1024) { }
    transform(value: any, metadata: ArgumentMetadata) {
        if (value.size > this.maxSize) {
            throw `文件大小不能超过 ${this.maxSize / 1024 / 1024} MB`
        }
        // TODO 其他验证，例如：文件类型，文件宽高等
        return value
    }
}